package com.woniu.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniu.common.ResultCom;
import com.woniu.entity.User;
import com.woniu.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/users")
public class UserControler {

    @Autowired
    IUserService iUserService;

    @PostMapping("/add")
    public ResultCom addUser(@RequestBody User user){

       Boolean success =  iUserService.save(user);
       return success ? ResultCom.success("添加成功") : ResultCom.error("添加失败");
    }

    public ResultCom updateUser(@RequestBody User user){

        Boolean success =  iUserService.updateById(user);
        return success ? ResultCom.success("更新成功") : ResultCom.error("更新失败");
    }
    public ResultCom deleteUser(@RequestParam Integer id){

        Boolean success =  iUserService.removeById(id);
        return success ? ResultCom.success("删除成功") : ResultCom.error("删除失败");
    }

    public ResultCom getUserList(@RequestParam Integer pageIndex, @RequestParam Integer pageSize){

        Page<User> datas =  iUserService.getUserList(pageIndex, pageSize);
        return datas!=null ? ResultCom.success("获取成功") : ResultCom.error("获取失败");
    }


}
